<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form>
            <p:panel  style="min-width: 100%;">  
                <f:facet name="header">
                    <h:outputLabel value="Purchase Order List"/>
                    <h:panelGrid columns="6" >
                        <h:outputLabel value="From Date"/>
                        <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                        </p:calendar>
                        <h:outputLabel value="To Date"/>
                        <p:calendar styleClass="dateTimePicker" id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                        </p:calendar>
                        <p:selectBooleanCheckbox value="#{searchController.reportKeyWord.additionalDetails}" itemLabel="Search All" />
                        <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createPoTableStore}"/>
                    </h:panelGrid>
                    <h:panelGrid columns="5" >
                        <h:outputLabel value="Distributor"/>
                        <h:outputLabel value="Po Number"/>
                        <h:outputLabel value="Po Value"/>
                        <h:outputLabel/><h:outputLabel/>
                        <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.toInstitution}" />
                        <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                        <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.netTotal}" />
                        <h:outputLabel/><h:outputLabel/>
                    </h:panelGrid>
                </f:facet>               


            </p:panel>



            <p:dataTable value="#{searchController.bills}" var="p">
                <p:column headerText="View PO">
                    <p:commandButton ajax="false" value="View PO" action="store_reprint_po">
                        <f:setPropertyActionListener value="#{p}" target="#{storeBillSearch.bill}"/>
                    </p:commandButton>
                </p:column>
                <p:column headerText="Approve at"  >
                    <h:outputLabel value="#{p.createdAt}" >
                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                    </h:outputLabel>
                    <br/>
                    <h:panelGroup rendered="#{p.cancelled}" >
                        <h:outputLabel style="color: red;" value="Cancelled at " />
                        <h:outputLabel style="color: red;" rendered="#{p.cancelled}"
                                       value="#{p.cancelledBill.createdAt}" >
                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                        </h:outputLabel>
                    </h:panelGroup>                   
                </p:column> 

                <p:column headerText="Approve by" >
                    <h:outputLabel value="#{p.creater.webUserPerson.name}" >                                      
                    </h:outputLabel>
                    <br/>
                    <h:panelGroup rendered="#{p.cancelled}" >
                        <h:outputLabel style="color: red;" value="Cancelled by " />
                        <h:outputLabel style="color: red;" rendered="#{p.cancelled}" value="#{p.cancelledBill.creater.webUserPerson.name}" >                                       
                        </h:outputLabel>
                    </h:panelGroup>                  
                </p:column>    

                <p:column headerText="Distributor">
                    <h:outputLabel  value="#{p.toInstitution.name}"/>
                </p:column>
                <p:column headerText="Po Number" >                   
                    <h:outputLabel  value="#{p.deptId}"/>
                </p:column>              
                <p:column headerText="Po Value">
                    <h:outputLabel value="#{p.netTotal}">
                        <f:convertNumber pattern="#,##0.00" />
                    </h:outputLabel>
                </p:column>
                <p:column>
                    <p:commandButton ajax="false" value="Recieve" action="store_grn" disabled="#{p.cancelled}" actionListener="#{storeGrnController.clearList()}">
                        <f:setPropertyActionListener target="#{storeGrnController.approveBill}" value="#{p}"/>
                    </p:commandButton>
                </p:column>
                <p:column headerText="GRNS">                   
                    <p:dataTable var="b" value="#{p.listOfBill}">                        
                        <p:column  >
                            <h:outputLabel  value="#{b.deptId}"/>
                        </p:column>
                        <p:column >
                            <h:outputLabel value="#{b.createdAt}" />
                            <br/>
                            <h:panelGroup rendered="#{b.cancelled}" >
                                <h:outputLabel style="color: red;" value="Cancelled at " />
                                <h:outputLabel style="color: red;" rendered="#{b.cancelled}"
                                               value="#{b.cancelledBill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                            </h:panelGroup>
                            <h:panelGroup rendered="#{b.refunded}" >
                                <h:outputLabel style="color: red;" value="Refunded at " />
                                <h:outputLabel style="color: red;" rendered="#{b.refunded}" 
                                               value="#{b.refundedBill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                            </h:panelGroup>
                        </p:column> 

                        <p:column >
                            <h:outputLabel value="#{b.creater.webUserPerson.name}" />                                      
                            <br/>
                            <h:panelGroup rendered="#{b.cancelled}" >
                                <h:outputLabel style="color: red;" value="Cancelled by " />
                                <h:outputLabel style="color: red;" rendered="#{b.cancelled}"
                                               value="#{b.cancelledBill.creater.webUserPerson.name}" >                                       
                                </h:outputLabel>
                            </h:panelGroup>
                            <h:panelGroup rendered="#{b.refunded}" >
                                <h:outputLabel style="color: red;" value="Refunded by " />
                                <h:outputLabel style="color: red;" rendered="#{b.refunded}"
                                               value="#{b.refundedBill.creater.webUserPerson.name}" >                         
                                </h:outputLabel>
                            </h:panelGroup>
                        </p:column> 
                        <p:column >
                            <h:outputLabel  value="#{b.invoiceNumber}"/>
                        </p:column>
                        <p:column >
                            <h:outputLabel value="#{b.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column>
                            <p:commandButton value="View Recive" action="store_reprint_grn">
                                <f:setPropertyActionListener target="#{storeBillSearch.bill}" value="#{b}"/>
                            </p:commandButton>
                        </p:column>

                    </p:dataTable>
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:define>  

</ui:composition>
